/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            queryStockManageInfo: {
                inoutOrders: [],
                shopHouses: [],
                total: 0,
                records: 1,
                moreCondition: false,
                shId: '',
                curOrder: {},
                conditions: {
                    warnFlag: '1',
                    prodName: '',
                    shId: '',
                    productId: '',
                    shopId: vc.getCurrentCommunity().shopId
                }
            }
        },
        _initMethod: function () {
            $that._listInoutOrder(DEFAULT_PAGE, DEFAULT_ROWS);
            $that._listShopHouses();
        },
        _initEvent: function () {
            vc.on('queryStockManage', 'listInoutOrder', function (_param) {
                $that._listInoutOrder(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('queryStockManage', 'notifyAuditInfo', function (_param) {
                $that._auditOrderState(_param);
            })
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listInoutOrder(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listInoutOrder: function (_page, _rows) {
                $that.queryStockManageInfo.conditions.page = _page;
                $that.queryStockManageInfo.conditions.row = _rows;
                var param = {
                    params: $that.queryStockManageInfo.conditions
                };
                param.params.productId = param.params.productId.trim();
                param.params.prodName = param.params.prodName.trim();
                //发送get请求
                vc.http.apiGet('/product.queryProductStock',
                    param,
                    function (json, res) {
                        var _queryStockManageInfo = JSON.parse(json);
                        $that.queryStockManageInfo.total = _queryStockManageInfo.total;
                        $that.queryStockManageInfo.records = _queryStockManageInfo.records;
                        $that.queryStockManageInfo.inoutOrders = _queryStockManageInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.queryStockManageInfo.records,
                            dataCount: $that.queryStockManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            //查询
            _queryShopHouseMethod: function () {
                $that._listInoutOrder(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetShopHouseMethod: function () {
                $that.queryStockManageInfo.conditions.prodName = "";
                $that.queryStockManageInfo.conditions.productId = "";
                $that.queryStockManageInfo.conditions.shId = "";
                $that._listInoutOrder(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.queryStockManageInfo.moreCondition) {
                    $that.queryStockManageInfo.moreCondition = false;
                } else {
                    $that.queryStockManageInfo.moreCondition = true;
                }
            },
            _toDetail: function (_inoutOrder) {
                vc.jumpToPage('/#/pages/goods/upShopHouseDetail?orderId=' + _inoutOrder.orderId);
            },
            _listShopHouses: function (_page, _rows) {
                var param = {
                    params: {
                        page: 1,
                        row: 100,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/shopHouse.queryShopHouse',
                    param,
                    function (json, res) {
                        var _shopHouseManageInfo = JSON.parse(json);
                        $that.queryStockManageInfo.shopHouses = _shopHouseManageInfo.data;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
        }
    });
})(window.vc);
